import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


//常量路由
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () => import('@/views/404'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  name: 'Layout',
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () => import('@/views/dashboard/index'),
    meta: {
      title: '首页',
      icon: 'dashboard'
    }
  }]
},

]

// 异步路由
export const allAsyncRoutes = [
  //权限管理
  {
    name: 'Acl',
    path: '/acl',
    component: Layout,
    redirect: '/acl/user/list',
    meta: {
      title: '权限管理',
      icon: 'el-icon-lock'
    },
    children: [
      {
        name: 'User',
        path: 'user/list',
        component: () => import('@/views/acl/user/list'),
        meta: {
          title: '用户管理',
        },
      },
      {
        name: 'Role',
        path: 'role/list',
        component: () => import('@/views/acl/role/list'),
        meta: {
          title: '角色管理',
        },
      },
      {
        name: 'RoleAuth',
        path: 'role/auth/:id',
        component: () => import('@/views/acl/role/roleAuth'),
        meta: {
          activeMenu: '/acl/role/list',
          title: '角色授权',
        },
        hidden: true,
      },
      {
        name: 'Permission',
        path: 'permission/list',
        component: () => import('@/views/acl/permission/list'),
        meta: {
          title: '菜单管理',
        },
      },
    ]
  },
  //数据管理
  {
    path: '/datamanage',
    name: 'Product',
    component: Layout,
    redirect: '/datamanage/userList',
    meta: {
      title: '数据管理',
      icon: 'el-icon-setting'
    },
    children: [{
      path: 'userList',
      name: 'Trademark',
      component: () => import('@/views/dataManage/userList'),
      meta: {
        title: '用户列表'
      }
    },
    {
      path: 'adminList',
      name: 'Attr',
      component: () => import('@/views/dataManage/adminList'),
      meta: {
        title: '管理员列表'
      }
    },
    {
      path: 'foodList',
      name: 'Sku',
      component: () => import('@/views/dataManage/foodList'),
      meta: {
        title: '食品列表'
      }
    },
    {
      path: 'orderList',
      name: 'Order',
      component: () => import('@/views/dataManage/orderList'),
      meta: {
        title: '订单列表'
      }
    },
    {
      path: 'shopList',
      name: 'Spu',
      component: () => import('@/views/dataManage/shopList'),
      meta: {
        title: '商家列表'
      }
    }
    ]
  },
  //添加数据
  {
    path: '/adddata',
    component: Layout,
    redirect: '/adddata/addfood',
    name: 'ActivityRule',
    meta: {
      title: '添加数据',
      icon: 'el-icon-plus'
    },
    children: [{
      path: 'addfood',
      name: 'RoleAuth',
      component: () => import('@/views/addData/addFood'),
      meta: {
        title: '添加商品'
      }
    },
    {
      path: 'addmerchant',
      name: 'Sku',
      component: () => import('@/views/addData/addmerchant'),
      meta: {
        title: '添加商铺'
      }
    }
    ]
  }
]

// 任意路由 // 404 page must be placed at the end !!!
export const randomRoute = {
  path: '*',
  redirect: '/404',
  hidden: true
}

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})


const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
